package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "菜单接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private JwtProperties jwtProperties;

    @GetMapping("/list")
    @ApiOperation("菜单查询")
    public Result<PageResult> getList(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult = categoryService.getList(categoryPageQueryDTO);
        return Result.success(pageResult);
    }
    @PutMapping ("/update")
    @ApiOperation("菜单分类修改")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result startOrStop(@PathVariable("status") Integer status, Long id){
        categoryService.startOrStop(status,id);
        return Result.success();
    }
    @GetMapping("/typeList")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> selectByType(Integer type){
        List<Category> list = categoryService.selectByType(type);
        return Result.success(list);
    }
    @PostMapping("/add")
    @ApiOperation("新增菜单分类")
    public Result add(@RequestBody CategoryDTO categoryDTO){
        categoryService.save(categoryDTO);
        return Result.success();
    }
    @GetMapping("/list2")
    @ApiOperation("根据分类查询")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }
}
